# Dependencies resolution -----------------------------------------------------

find_package(Qt4 REQUIRED)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/3rdParty )
find_package(openssl REQUIRED)
find_package(crypto REQUIRED)
find_package(curl REQUIRED)

# Version source file generation ----------------------------------------------

configure_file( ${PROJECT_SOURCE_DIR}/PopupClientQt/popup.version.rc
                ${PROJECT_SOURCE_DIR}/PopupClientQt/src/PopupVersion.cpp
                @ONLY )

# Inputs ----------------------------------------------------------------------

file( GLOB PopupClientQt_SOURCES     ./src/*.cpp )
file( GLOB PopupClientQt_FORMS       ./rc/forms/*.ui )
file( GLOB PopupClientQt_QRC         ./rc/popup.qrc )
file( GLOB PopupClientQt_TS          ./rc/translations/*ts )
if (${CMAKE_SYSTEM_NAME} STREQUAL Windows)
file( GLOB PopupClientQt_WRC         ./rc/popup-windows.rc )
endif (${CMAKE_SYSTEM_NAME} STREQUAL Windows)

set ( PopupClientQt_HEADERS include/PopupClientThread.hpp
                            include/PopupUpdateManager.hpp
                            include/PopupImageViewer.hpp
                            include/PopupGuiCore.hpp
                            include/PopupSetupDialog.hpp
                            include/PopupMessageDialog.hpp
                            include/PopupMessageWidget.hpp
                            include/PopupThreadStartWidget.hpp
                            include/PopupThreadWidget.hpp
                            include/PopupLoginDialog.hpp
                            include/PopupThreadTextWidget.hpp
                            include/PopupUsersTableModel.hpp
                            include/PopupProgressWidget.hpp 
                            include/PopupUsersWidget.hpp 
                            include/PopupUsersDialog.hpp 
                            include/PopupUsersManager.hpp
                            include/PopupCanvassWidget.hpp
                            include/PopupCanvassChoice.hpp
                            include/PopupCanvassResult.hpp 
                            include/PopupUserProfileFrame.hpp
                            include/PopupNotificationFrame.hpp
                            include/PopupLogsDialog.hpp
                            include/PopupTransfersDialog.hpp
                            include/PopupCustomButton.hpp )

# Includes --------------------------------------------------------------------

include_directories( ${curl_INCLUDE_DIRS} )
include_directories( ${PROJECT_SOURCE_DIR}/PopupLibrary/include )
include_directories( ${PROJECT_SOURCE_DIR}/PopupLibOSAL/include )
include_directories( ${CMAKE_CURRENT_BINARY_DIR})
include_directories( ./include )


# QT Specific -----------------------------------------------------------------

include(${QT_USE_FILE})
#add_definitions( ${QT_DEFINITIONS} )

QT4_WRAP_CPP( PopupClientQt_HEADERS_MOC ${PopupClientQt_HEADERS} )
QT4_WRAP_UI( PopupClientQt_FORMS_HEADERS ${PopupClientQt_FORMS} )
QT4_ADD_RESOURCES( PopupClientQt_RCC ${PopupClientQt_QRC} )
QT4_ADD_TRANSLATION( PopupClientQt_QM ${PopupClientQt_TS} )


# Final target ----------------------------------------------------------------

add_executable( PopupClientQt ${PopupClientQt_SOURCES}
                              ${PopupClientQt_HEADERS_MOC}
                              ${PopupClientQt_FORMS_HEADERS}
                              ${PopupClientQt_RCC} 
                              ${PopupClientQt_QM} 
                              ${PopupClientQt_WRC})

target_link_libraries( PopupClientQt ${QT_LIBRARIES} 
                                     popup-static
                                     osal-static
                                     ${openssl_LIBRARY}
                                     ${crypto_LIBRARY}
                                     ${curl_LIBRARY})

install( TARGETS PopupClientQt DESTINATION ${POPUP_INSTALL_DIR}/bin )

# OS specific stuff -----------------------------------------------------------

# Windows specific
if (${CMAKE_SYSTEM_NAME} STREQUAL Windows)
  set(CMAKE_RC_COMPILER_INIT ${POPUP_TARGET}-windres)
  ENABLE_LANGUAGE(RC)
  SET(CMAKE_RC_COMPILE_OBJECT
      "<CMAKE_RC_COMPILER> -O coff -o <OBJECT> <SOURCE>")
  find_package(pthread REQUIRED)
  include_directories( ${pthread_INCLUDE_DIRS} )
  target_link_libraries( PopupClientQt ${pthread_LIBRARY} ws2_32 -static-libgcc -mwindows )
endif (${CMAKE_SYSTEM_NAME} STREQUAL Windows)

# Linux specific
if (${CMAKE_SYSTEM_NAME} STREQUAL Linux)
  target_link_libraries( PopupClientQt dl pthread) 
endif (${CMAKE_SYSTEM_NAME} STREQUAL Linux)

